package com.woniuxy.reader.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.woniuxy.reader.entity.Author;
import com.woniuxy.reader.entity.Editor;
import com.woniuxy.reader.entity.Manager;
import com.woniuxy.reader.mapper.AuthorMapper;
import com.woniuxy.reader.mapper.EditorMapper;
import com.woniuxy.reader.mapper.ManagerMapper;
import com.woniuxy.reader.service.EditorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.reader.vo.AuthorVOO;
import com.woniuxy.reader.vo.EditorVO;
import com.woniuxy.reader.vo.EditorVOO;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.management.Query;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zh_o
 * @since 2020-10-12
 */
@Service
public class EditorServiceImpl extends ServiceImpl<EditorMapper, Editor> implements EditorService {
    @Resource
    private EditorMapper editorMapper;



    @Override
    public List<AuthorVOO> selectSignUp(String editortel) {
        return editorMapper.selectSignUp(editortel);
    }

    @Override
    public List<EditorVOO> selectAllSignEditor() {
        return editorMapper.selectAllSignEditor();
    }

    @Override
    public String insertEditor(String tel) {
        if (editorMapper.selectList(new QueryWrapper<Editor>().eq("editor_tel", tel)).size() == 0) {
            Editor temp = new Editor();
            Md5Hash md5Hash = new Md5Hash("11", "woNiuReAdeR*79", 1024);

            temp.setEditorTel(tel);
            temp.setPassword(md5Hash.toString());
            editorMapper.insert(temp);
            return "新增成功";
        } else {
            return "该手机号已存在";
        }
    }

    @Override
    public Editor selectByTel(String tel) {
        return editorMapper.selectOne(new QueryWrapper<Editor>().eq(StringUtils.isNotBlank(tel),"editor_tel",tel));
    }

    @Override
    public String rejectSgin(int authorid) {
        editorMapper.updateByAuthorId(authorid);
        return "驳回成功";
    }

}
